package hoangbn.apps.adapter;

import hoangbn.apps.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends ArrayAdapter<String> {

	private Context context;
	private String[] objects;
	private int[] imgs;
	private float[] prices;

	public MenuAdapter(Context context, int resource, String[] objects,
			int[] imgs, float[] price) {
		super(context, resource, objects);
		this.context = context;
		this.objects = objects;
		this.imgs = imgs;
		this.prices = price;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = null;
		LayoutInflater inflater = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			rowView = inflater.inflate(R.layout.activity_menu, parent, false);
		} else {
			rowView = convertView;
		}
		ImageView ivItemImg = (ImageView) rowView.findViewById(R.id.ivItemImg);
		TextView tvItemName = (TextView) rowView.findViewById(R.id.tvItemName);
		TextView tvItemPrice = (TextView) rowView
				.findViewById(R.id.tvItemPrice);
		ivItemImg.setImageResource(imgs[position]);
		tvItemName.setText(objects[position]);
		tvItemPrice.setText("$" + String.valueOf(prices[position]));
		return rowView;
	}
}
